package com.springapp.mvc.service.impl;

import com.springapp.mvc.dao.bean.Location;
import com.springapp.mvc.dao.mapper.EXLocationMapper;
import com.springapp.mvc.service.Interface.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 6/26/2018.
 */
@Service
public class LocationServiceImpl implements LocationService
{

    @Autowired(required = false)
    private EXLocationMapper mExLocationMapper;

    @Override
    public long insertCurrentLocation(float lon, float lat,String address)
    {
        System.out.println("long:"+lon + ";  lat:"+lat);
        Location location = new Location();
        location.setLat(lat);
        location.setLon(lon);
        location.setAddress(address);
        location.setTime(System.currentTimeMillis());
    //    return mExLocationMapper.insert(location);
        mExLocationMapper.insertSelectKey(location);
        return location.getId();
    }

    @Override
    public int getLocationCount()
    {
        return mExLocationMapper.getTotalNum();
    }

    @Override
    public List<Location> queryLocationPaged(int limit, int offset, String sortPro, String sortType)
    {
        return mExLocationMapper.querylocationPaged(limit, offset, sortPro, sortType);
    }

    @Override
    public int deleteLocation(int locationId)
    {
        return mExLocationMapper.deleteByPrimaryKey((long) locationId);
    }

    @Override
    public Location queryLocationById(long locationId)
    {
        return mExLocationMapper.selectByPrimaryKey(locationId);
    }
}
